<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>表单控件-购物车1</title>
    <script src="lib/vue.js"></script>
</head>

<body>
    <div id="box">
        <ul>
            <li v-for="data in datalist" :key="data.id">
                <input type="checkbox" v-model="checkgroup" :value="data">
                {{data}}
            </li>
            {{checkgroup}}
            <p>总金额计算:{{getSum()}}</p>
        </ul>
    </div>

    <script>
        new Vue({
            el: "#box",
            data: {
                checkgroup: [],
                datalist: [{
                        name: "商品1",
                        price: 10,
                        number: 1,
                        id: "1"
                    },
                    {
                        name: "商品2",
                        price: 20,
                        number: 2,
                        id: "2"
                    },
                    {
                        name: "商品3",
                        price: 30,
                        number: 3,
                        id: "3"
                    }
                ]
            },
            methods: {
                getSum() {
                    var sum = 0;
                    for (var i in this.checkgroup) {
                        sum += this.checkgroup[i].number * this.checkgroup[i].price
                    }
                    return sum
                }
            }
        })
    </script>

</body>

</html>